home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / programr / atre27.exe / ATREE_27 / INCLUDE / ATREE.H < prev    next >
C/C++ Source or Header  |  1992-08-01  |  9KB  |  222 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** atree.h                                                             ****
  4.  ****                                                                     ****
  5.  **** atree release 2.7                                                   ****
  6.  **** Copyright (C) A. Dwelly, R. Manderscheid, M. Thomas, W.W. Armstrong ****
  7.  ****               1991, 1992                                            ****
  8.  ****                                                                     ****
  9.  **** License:                                                            ****
  10.  **** A royalty-free license is granted for the use of this software for  ****
  11.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ****
  12.  **** modified provided this notice appears in its entirety and unchanged ****
  13.  **** in all derived source programs.  Persons modifying the code are     ****
  14.  **** requested to state the date, the changes made and who made them     ****
  15.  **** in the modification history.                                        ****
  16.  ****                                                                     ****
  17.  **** Patent License:                                                     ****
  18.  **** The use of a digital circuit which transmits a signal indicating    ****
  19.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  20.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  21.  **** W. W. Armstrong, President.  A royalty-free license is granted      ****
  22.  **** by the company to use this patent for NON_COMMERCIAL PURPOSES ONLY  ****
  23.  **** to adapt logic trees using this program and its modifications.      ****
  24.  ****                                                                     ****
  25.  **** Limited Warranty:                                                   ****
  26.  **** This software is provided "as is" without warranty of any kind,     ****
  27.  **** either expressed or implied, including, but not limited to, the     ****
  28.  **** implied warrantees of merchantability and fitness for a particular  ****
  29.  **** purpose.  The entire risk as to the quality and performance of the  ****
  30.  **** program is with the user.  Neither the authors, nor the             ****
  31.  **** University of Alberta, its officers, agents, servants or employees  ****
  32.  **** shall be liable or responsible in any way for any damage to         ****
  33.  **** property or direct personal or consequential injury of any nature   ****
  34.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  35.  **** or any other party as a consequence of the use or disposition of    ****
  36.  **** this software.                                                      ****
  37.  ****                                                                     ****
  38.  **** Modification history:                                               ****
  39.  ****                                                                     ****
  40.  **** 90.05.09 Initial implementation, A.Dwelly                           ****
  41.  **** 91.07.15 Release 2, Rolf Manderscheid                               ****
  42.  **** 92.27.02 Release 2.5, Monroe Thomas                                 ****
  43.  **** 92.03.07 Release 2.6, Monroe Thomas                                 ****
  44.  **** 92.01.08 Release 2.7, Monroe Thomas                                 ****
  45.  ****                                                                     ****
  46.  *****************************************************************************/
  47.  
  48. /*****************************************************************************
  49.  ****                                                                     ****
  50.  **** atree                                                               ****
  51.  ****                                                                     ****
  52.  **** An atree is the fundamental structure used by these routines; it is ****
  53.  **** a binary tree with nodes taking one of four logical functions, AND, ****
  54.  **** OR, LEFT or RIGHT depending on initialization or the training it    ****
  55.  **** has undergone.  The tree is randomly connected to input variables   ****
  56.  **** and their complements.                                              ****
  57.  ****                                                                     ****
  58.  *****************************************************************************/
  59.  
  60. // windows.h must be included before atree.h
  61.  
  62. #ifndef __ATREE_H
  63. #define __ATREE_H
  64.  
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif  // __cplusplus
  68.  
  69. #ifndef __STDIO_H
  70. #include <stdio.h>
  71. #endif
  72.  
  73. #ifndef __STDLIB_H
  74. #include <stdlib.h>
  75. #endif
  76.  
  77. #ifndef __ALLOC_H
  78. #include <alloc.h>
  79. #endif
  80.  
  81. #ifndef __STRING_H
  82. #include <string.h>
  83. #endif
  84.  
  85. #ifndef __MATH_H
  86. #include <math.h>
  87. #endif
  88.  
  89. #ifndef __ASSERT_H
  90. #include <assert.h>
  91. #endif
  92.  
  93. #ifndef __CTYPE_H
  94. #include <ctype.h>
  95. #endif
  96.  
  97. #ifndef __ERRNO_H
  98. #include <errno.h>
  99. #endif
  100.  
  101. #ifndef __PROCESS_H
  102. #include <process.h>
  103. #endif
  104.  
  105. #ifndef __BV_H
  106. #include "bv.h"
  107. #endif
  108.  
  109. typedef union atree_type {
  110.  
  111.     union atree_node_type {
  112.     union atree_node_type far *next;    // 4 byte pointer for free list management
  113.     struct {
  114.       char cnt_right;
  115.       char cnt_left;
  116.       unsigned char tag;
  117.       unsigned char sig_right;
  118.       unsigned char sig_left;
  119.       union atree_type far *child[2];
  120.     } data;                             // structure is 8 bytes long
  121.     } node;                               // union is 8 bytes long
  122.  
  123.   union atree_leaf_type {
  124.     union atree_leaf_type far *next;    // 4 byte pointer
  125.     struct {
  126.       unsigned int bit_no;
  127.       unsigned char tag;
  128.       unsigned char comp;
  129.     } data;                             // structure is 4 bytes long
  130.   } leaf;                                // union is 4 bytes long
  131.  
  132. } atree;                                // union is 8 bytes long
  133.  
  134. typedef atree far *LPATREE;                // common Windows convention
  135.  
  136. #define c_tag           node.data.tag       // common field tags
  137. #define l_bit_no        leaf.data.bit_no
  138. #define l_comp          leaf.data.comp
  139. #define n_sig_right     node.data.sig_right
  140. #define n_sig_left      node.data.sig_left
  141. #define n_cnt_right     node.data.cnt_right
  142. #define n_cnt_left      node.data.cnt_left
  143. #define n_child            node.data.child
  144. #define n_child_right   node.data.child[1]
  145. #define n_child_left    node.data.child[0]
  146.  
  147. typedef union atree_node_type atree_node;
  148. typedef atree_node far *LPATREE_NODE;   // common Windows convention
  149.  
  150. typedef union atree_leaf_type atree_leaf;
  151. typedef atree_leaf far *LPATREE_LEAF;   // common Windows convention
  152.  
  153. typedef struct fast_tree_struct {
  154.   struct fast_tree_struct far *next[2];
  155.   int bit_no;
  156.   int comp;
  157. } fast_tree;                            // struct is 12 bytes long
  158.  
  159. typedef fast_tree far *LPFAST_TREE;     // common Windows convention
  160.  
  161. typedef struct code_struct {
  162.   int vector_count;
  163.   int width;
  164.   float low;
  165.   float high;
  166.   float step;
  167.   LPBIT_VEC vector;
  168. } code_t;                               // struct is 22 bytes long
  169.  
  170. typedef code_t far *LPCODE_T;           // common Windows convention
  171.  
  172. /* Public function prototypes */
  173.  
  174. void FAR PASCAL         Windows_Interrupt(DWORD);
  175.  
  176. void FAR PASCAL         atree_init(HANDLE, HWND);
  177. void FAR PASCAL         atree_quit(void);
  178. LPATREE FAR PASCAL      atree_create(int, int);
  179. void FAR PASCAL         atree_print(LPATREE, FILE *, int);
  180. BOOL FAR PASCAL         atree_eval(LPATREE, LPBIT_VEC);
  181. int FAR PASCAL          atree_train(LPATREE, LPBIT_VEC, LPBIT_VEC,int,int,int,int,int);
  182. LPBIT_VEC FAR PASCAL    atree_rand_walk(int, int, int);
  183. void FAR PASCAL         atree_free(LPATREE);
  184.  
  185. LPATREE FAR PASCAL      atree_fold(LPATREE);
  186. LPFAST_TREE FAR PASCAL  atree_compress(LPATREE);
  187. BOOL FAR PASCAL         atree_fast_eval(LPFAST_TREE, LPBIT_VEC);
  188. void FAR PASCAL         atree_fast_print(LPFAST_TREE, FILE *);
  189.  
  190. int FAR PASCAL          atree_store(LPATREE, LPSTR);
  191. LPATREE FAR PASCAL      atree_load(LPSTR);
  192. int FAR PASCAL          atree_write(FILE *, LPATREE);
  193. LPATREE FAR PASCAL      atree_read(FILE *);
  194.  
  195. int FAR PASCAL          atree_set_code(LPCODE_T, double, double, int, int, int);
  196. int FAR PASCAL          atree_encode(double, LPCODE_T);
  197. int FAR PASCAL          atree_decode(LPBIT_VEC, LPCODE_T);
  198. int FAR PASCAL          atree_write_code(FILE *, LPCODE_T);
  199. LPCODE_T FAR PASCAL     atree_read_code(FILE *, LPCODE_T);
  200.  
  201. /* some public Macros */
  202.  
  203. #define MEMCHECK(p) \
  204.         if (p == NULL){ \
  205.                          MessageBox(NULL,"Could not allocate requested memory",\
  206.                          "atree",MB_OK | MB_ICONSTOP);\
  207.                          PostQuitMessage(0);\
  208.                          exit(0);\
  209.                         }
  210. #define RANDOM(b) (rand() % (b))
  211. #define Malloc(cb) farmalloc(cb)
  212. #define Free(p)    farfree(p)
  213.  
  214. #define IDD_ATREE_EPOCH 100
  215. #define IDD_ATREE_CORRECT 101
  216. #define IDD_ATREE_ACTUAL 102
  217.  
  218. #ifdef __cplusplus
  219. }
  220. #endif  // __cplusplus
  221.  
  222. #endif    // __ATREE_H